package org.administer.contaroller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.administer.dao.ChatDao;
import org.administer.dao.CrmplanDao;
import org.administer.pojo.CrmChat;
import org.administer.pojo.CrmPlan;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/plan")
public class PlanController {
    @Autowired
    private CrmplanDao crmplanDao;
    @Autowired
    private ChatDao chatDao;
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(CrmPlan crmPlan) throws Exception{
        Map<String,Object> map=new HashMap<>();
        System.out.println(crmplanDao.getlist(crmPlan).size());
        if(crmplanDao.getlist(crmPlan).size()>0){
            map.put("code",0);
            map.put("msg","抱歉,已制定开发计划...");
            return map;
        }
        System.out.println(crmplanDao.getlist(crmPlan).size());
        crmplanDao.add(crmPlan);
        return map;
    }
    @RequestMapping("/select")
    @ResponseBody
    @RequiresPermissions("plan:select")
    public Map<String,Object> select(CrmPlan crmPlan,@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<CrmPlan> planPage = PageHelper.startPage(page,limit);
        map.put("code",0);
        map.put("msg",null);
        map.put("data", crmplanDao.getlist(crmPlan));
        map.put("count",planPage.getTotal());
        return map;
    }
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(CrmPlan crmPlan) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmplanDao.update(crmPlan);
        return map;
    }
    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> del(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmplanDao.del(id);
        return map;
    }
    @RequestMapping("/get")
    @ResponseBody
    public Map<String,Object> get(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmplanDao.get(id);
        return map;
    }
    @RequestMapping("/updatajihua")
    @ResponseBody
    public Map<String,Object> updatajihua(CrmChat crmChat) throws Exception{
        Map<String,Object> map=new HashMap<>();
        chatDao.updatajihua(crmChat);
        return map;
    }

}
